/*
* 质量核验详情（不可操作）
* */

import 'dart:convert';

import 'package:center_beijing/api/component_api.dart';
import 'package:center_beijing/api/quality_api.dart';
import 'package:center_beijing/common/QRScan.dart';
import 'package:center_beijing/common/notification.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:center_beijing/config/routeConfig.dart';
import 'package:center_beijing/widgets/custom_loading_widget.dart';
import 'package:center_beijing/widgets/selectRow_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:left_scroll_actions/cupertinoLeftScroll.dart';
import 'package:left_scroll_actions/global/actionListener.dart';

class QualityFormDetail extends StatefulWidget {
  @override
  _QualityFormDetailState createState() => _QualityFormDetailState();
}

class _QualityFormDetailState extends State<QualityFormDetail> with SingleTickerProviderStateMixin {
  AnimationController _controller;
  CustomLoading loading = CustomLoading.withMessage('提交中...');
  var currentSpot = Get.arguments;
  var samplingTime = ''; //抽检时间
  List selectList = [];

  var spotCheck = Map();
  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    this.getSpotCheckDetail();
  }

/*
  * 获取抽检详情
  * */
  getSpotCheckDetail() async {
    var pass = {"id": currentSpot['id']};
    var result = await getElementSpotCheckEx(pass);
    if (result != null && result['hasError'] == null) {
      this.setState(() {
        spotCheck = result;
        selectList = result['elementSpotCheckInfoList'] == null
            ? []
            : result['elementSpotCheckInfoList'];
      });
    }
  }

  @override
  void dispose() {
    _controller.dispose();
    loading.dismiss();
    super.dispose();
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('质量抽检'),
        ),
        body: Container(
          color: Styles.MainBackgroundColor,
          padding: EdgeInsets.fromLTRB(
              0, 0, 0, MediaQuery.of(context).padding.bottom),
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing16,
                      Styles.spacing16, Styles.spacing16),
                  child: Text(
                    '任务单号:${this.spotCheck['checkNo']}(自动生成)',
                    style: TextStyle(
                        color: Styles.DetailColor, fontSize: Styles.Middle16Font),
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(Styles.spacing16, 0,
                      Styles.spacing16, Styles.spacing16),
                  child: Text(
                    '抽检时间:${this.spotCheck['checkDateStr']}',
                    style: TextStyle(
                        color: Styles.DetailColor, fontSize: Styles.Middle16Font),
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,0,
                      Styles.spacing16, Styles.spacing8),
                  child: Text(
                    '抽样构件(${selectList.length.toString()})',
                    style: TextStyle(
                        color: Styles.DetailColor, fontSize: Styles.Middle16Font),
                  ),
                ),
                Column(
                  children: this.selectList.map((item) {
                    return GestureDetector(
                      onTap: (){
                        Get.toNamed(RouteConfig.qualityElementDetail,arguments: item);
                      },
                      child: Container(
                        color: Colors.white,
                        padding: EdgeInsets.fromLTRB(
                            Styles.spacing8,
                            Styles.spacing8,
                            Styles.spacing8,
                            Styles.spacing8),
                        margin: EdgeInsets.only(top: Styles.spacing8),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Row(
                              children: [
                                Container(
                                  margin: EdgeInsets.only(
                                      right: Styles.spacing8),
                                  height: 20.h,
                                  width: 4.w,
                                  color: Styles.BlueColor,
                                ),
                                Text(
                                  (item['elementInfoVO'] != null &&
                                      item['elementInfoVO']['compKind']
                                      ['compKindName'] !=
                                          null)
                                      ? item['elementInfoVO']['compKind']
                                  ['compKindName']
                                      : '--',
                                  style: TextStyle(
                                      color: Styles.DetailColor,
                                      fontSize: Styles.Middle16Font),
                                ),
                              ],
                            ),
                            Container(
                              margin: EdgeInsets.fromLTRB(
                                  Styles.spacing8, 0, Styles.spacing8, 0),
                              child: Column(
                                crossAxisAlignment:
                                CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    item['elementInfoVO'] != null &&
                                        item['elementInfoVO']['code'] !=
                                            null
                                        ? item['elementInfoVO']['code']
                                        : '--',
                                    style: TextStyle(
                                        color: Styles.DetailColor,
                                        fontSize: Styles.Middle16Font),
                                  ),
                                  Text(
                                    (item['elementInfoVO'] != null &&
                                        item['elementInfoVO']
                                        ['orderInfo'] !=
                                            null &&
                                        item['elementInfoVO']
                                        ['orderInfo']
                                        ['orderName'] !=
                                            null)
                                        ? item['elementInfoVO']['orderInfo']
                                    ['orderName']
                                        : '--',
                                    style: TextStyle(
                                        color: Styles.LeftTitleColor,
                                        fontSize: Styles.NormalFont),
                                  ),
                                  Text(
                                    item['elementInfoVO'] != null &&
                                        item['elementInfoVO']
                                        ['levelPath'] !=
                                            null
                                        ? (item['elementInfoVO']
                                    ['levelPath']
                                        .split('&_&_&'))
                                        .join('-')
                                        : '--',
                                    style: TextStyle(
                                        color: Styles.LeftTitleColor,
                                        fontSize: Styles.NormalFont),
                                  ),
                                ],
                              ),
                            )
                          ],
                        ),
                      ),
                    );
                  }).toList(),
                )
              ],
            ),
          ),
        ),
    );
  }
}
